/**
 * @date 2006-5-9 16:36:14
 *
 */
package org.nanhill.moo.dao.hibernate;

import java.util.Collection;
import java.util.List;

import org.nanhill.moo.dao.CategoryDao;
import org.nanhill.moo.domain.Category;
import org.nanhill.support.hibernate.HibernateEntityManager;

/**
 * @author alin [xalinx at gmail dot com]
 * 
 */
public class CategoryDaoImpl extends HibernateEntityManager<Category, Long>
		implements CategoryDao {

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.nanhill.moo.dao.CategoryDao#find(java.lang.String)
	 */
	public Category findByName(String categoryName) {
		return findOne("from Category p where p.name = ?", categoryName);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.nanhill.moo.dao.CategoryDao#findChilds(long)
	 */
	@SuppressWarnings("unchecked")
	public Collection<Category> findChilds(long cid) {
		return findList("from Category p where p.parent.id = ?", cid);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.nanhill.moo.dao.CategoryDao#findRootChilds()
	 */
	@SuppressWarnings("unchecked")
	public List<Category> findRootChilds() {
		return findList("from Category p where p.parent = null");
	}

}
